/*
 * @Description: 行按钮配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2025-07-28 21:55:31
 * @LastEditTime: 2025-09-15 18:03:39
 */
import { defineRowBtnsOptions } from "@/components/TablePage/predefined";
import useEditOptions from "./useEditOptions";
import { addPerm, updatePerm, delPerm } from "@/api/sys";

export default defineRowBtnsOptions(() => ({
  addRequest: addPerm,
  editRequest: updatePerm,
  delRequest: delPerm,
  editDialogProps: { title: "编辑权限" },
  addDialogProps: { title: "新增权限" },
  editFormOptions: useEditOptions(),
  addFormOptions: useEditOptions(),
  beforeShowAddDialog(rowData) {
    // 新增时设置当前行为父节点
    rowData.value = {
      pid: rowData.value.id,
      orderRank: 0,
      keepAlive: true,
      internal: true,
      blank: false,
    } as Permission;
  },
  beforeEditSubmit(formData) {
    formData.value.name = formData.value.title;
    delete formData.value.children;
  },
  beforeAddSubmit(formData) {
    formData.value.name = formData.value.title;
  },
}));
